<h1>动态内存 - free</h1>


  <p>原型：extern void free(void *p);</p>
  
  <p>用法：#include &lt;alloc.h></p>
  
  <p>功能：释放指针p所指向的的内存空间。</p>
  
  <p>说明：p所指向的内存空间必须是用calloc,malloc,realloc所分配的内存。
        如果p为NULL或指向不存在的内存块则不做任何操作。</p>
  
  举例：<pre><code class="language-c">
      // free.c
      
      #include &lt;syslib.h>
      #include &lt;alloc.h>

      main()
      {
        char *p;
        
        clrscr();        // clear screen
        textmode(0x00);

        p=(char *)malloc(100);
        if(p)
          printf("Memory Allocated at: %x",p);
        else
          printf("Not Enough Memory!\n");
          
        getchar();
        free(p);         // release memory to reuse it

        p=(char *)calloc(100,1);
        if(p)
          printf("Memory Reallocated at: %x",p);
        else
          printf("Not Enough Memory!\n");

        free(p);         // release memory at program end
        
        getchar();
        return 0;
      }
  </code></pre>相关函数：<a href="calloc.html">calloc</a>,<a href="malloc.html">malloc</a>,<a href="realloc.html">realloc</a>

